﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;


namespace Xiaov.SmartWeb.Application.HXZB
{
    public partial class ZyzbRightData : System.Web.UI.Page
    {
        string zbbm = "", dwbm = "", nf = "", yf = "", type = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                #region 获取参数
                if (Request.QueryString["zbbm"] != null)
                {
                    zbbm = Request.QueryString["zbbm"].ToString();
                }
                if (Request.QueryString["dwbm"] != null)
                {
                    dwbm = Request.QueryString["dwbm"].ToString();
                }
                if (Request.QueryString["nf"] != null && Request.QueryString["yf"] != null)
                {
                    nf = Request.QueryString["nf"].ToString();
                    yf = Request.QueryString["yf"].ToString();
                }
                if (Request.QueryString["type"] != null)//数据信息 标题，本年数据，去年数据
                {
                    type = Request.QueryString["type"].ToString();
                }
                #endregion
                DataSet ds = null;
                switch (zbbm)
                {
                    #region 工业总产值
                    case "TG030003":
                        ds = InitGyzcz();
                        break;
                    #endregion
                    #region 工业销售产值
                    case "TG030004":
                        ds = InitGyxscz();
                        break;
                    #endregion
                    #region 原油产量
                    case "TG030008":
                        ds = InitYycl();
                        break;
                    #endregion
                    #region 天然气产量
                    case "TG030026":
                        ds = InitTrqcl();
                        break;
                    #endregion
                    #region 利润总额
                    case "TG820013":
                        ds = InitLrze();
                        break;
                    #endregion
                    #region 原油递减率
                    case "TG070031":
                        ds = InitYydjl();
                        break;
                    #endregion
                    #region 能源合计
                    case "NH6111":
                        ds = InitNyhj();
                        break;
                    #endregion
                    default:
                        break;
                }
                #region 输出数据
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (ds.Tables[0].Rows[i]["bnlj"].ToString() == "")
                        {
                            ds.Tables[0].Rows[i]["bnlj"] = 0;
                        }
                        if (ds.Tables[0].Rows[i]["qntqlj"].ToString() == "")
                        {
                            ds.Tables[0].Rows[i]["qntqlj"] = 0;
                        }
                        if (type == "title")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["yf"].ToString() + "月\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["yf"].ToString() + "月");
                            }
                        }
                        else if (type == "bnlj")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["bnlj"].ToString() + "\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["bnlj"].ToString());
                            }
                        }
                        else if (type == "qntq")
                        {
                            if (i != ds.Tables[0].Rows.Count - 1)
                            {
                                Response.Write(ds.Tables[0].Rows[i]["qntqlj"].ToString() + "\t");
                            }
                            else
                            {
                                Response.Write(ds.Tables[0].Rows[i]["qntqlj"].ToString());
                            }
                        }
                    }
                    Response.End();
                }
                #endregion              
            }
        }

        #region 工业总产值
        protected DataSet InitGyzcz()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select b.yf,a.bnlj bnlj,b.bnlj qntqlj from ");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030003' and nf={1} and yf<={0} and dwbm='{2}') a,");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030003' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
            sbSql.Append("where a.yf(+)=b.yf ");
            sbSql.Append("order by to_number(b.yf)");
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, "HB"));
            return ds;
        }        
        #endregion

        #region 工业销售产值
        protected DataSet InitGyxscz()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select b.yf,a.bnlj bnlj,b.bnlj qntqlj from ");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030004' and nf={1} and yf<={0} and dwbm='{2}') a,");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030004' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
            sbSql.Append("where a.yf(+)=b.yf ");
            sbSql.Append("order by to_number(b.yf)");
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, "HB"));
            return ds;
        }
        #endregion

        #region 原油产量
        protected DataSet InitYycl()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select b.yf,a.bnlj bnlj,b.bnlj qntqlj from ");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030008' and nf={1} and yf<={0} and dwbm='{2}') a,");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030008' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
            sbSql.Append("where a.yf(+)=b.yf ");
            sbSql.Append("order by to_number(b.yf)");
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, "HB"));
            return ds;
        }   
        #endregion

        #region 天然气产量
        protected DataSet InitTrqcl()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select b.yf,a.bnlj bnlj,b.bnlj qntqlj from ");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030026' and nf={1} and yf<={0} and dwbm='{2}') a,");
            sbSql.Append("(select * from tg03 t WHERE zbbm='TG030026' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
            sbSql.Append("where a.yf(+)=b.yf ");
            sbSql.Append("order by to_number(b.yf)");
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, "HB"));
            return ds;
        }    
        #endregion

        #region  利润总额
        protected DataSet InitLrze()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select b.yf,a.bnlj bnlj,b.bnlj qntqlj from ");
            sbSql.Append("(select * from tg82 t WHERE zbbm='TG820013' and nf={1} and yf<={0} and dwbm='{2}') a,");
            sbSql.Append("(select * from tg82 t WHERE zbbm='TG820013' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
            sbSql.Append("where a.yf(+)=b.yf ");
            sbSql.Append("order by to_number(b.yf)");
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, "HB"));
            return ds;
        }
        #endregion

        #region 原油递减率
        protected DataSet InitYydjl()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select b.yf,a.bnlj bnlj,b.bnlj qntqlj from ");
            sbSql.Append("(select * from tg07 t WHERE zbbm='TG070031' and nf={1} and yf<={0} and dwbm='{2}') a,");
            sbSql.Append("(select * from tg07 t WHERE zbbm='TG070031' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
            sbSql.Append("where a.yf(+)=b.yf ");
            sbSql.Append("order by to_number(b.yf)");
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, "HB"));
            return ds;
        }     
        #endregion

        #region 能源合计
        protected DataSet InitNyhj()
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append("select b.yf,a.xHhj bnlj,b.xHhj qntqlj from ");
            sbSql.Append("(select * from NH61 t WHERE zbbm='NH6111' and nf={1} and yf<={0} and dwbm='{2}') a,");
            sbSql.Append("(select * from NH61 t WHERE zbbm='NH6111' and nf={1}-1 and yf<={0} and dwbm='{2}') b ");
            sbSql.Append("where a.yf(+)=b.yf ");
            sbSql.Append("order by to_number(b.yf)");
            DataSet ds = Maticsoft.DBUtility.DbHelperOra.Query(string.Format(sbSql.ToString(), "12", nf, "HB"));
            return ds;
        }
        #endregion
    }
}